home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / OLEDIALG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.3 KB  |  184 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.10  $
  6. //
  7. // Implementation of class TOleDialog. This defines the basic behavior of all
  8. // Ole dialogs.
  9. //----------------------------------------------------------------------------
  10. #define INC_OLE2
  11. #include <owl/pch.h>
  12. #if !defined(OWL_OLEDIALG_H)
  13. # include <owl/oledialg.h>
  14. #endif
  15.  
  16. OWL_DIAGINFO;
  17.  
  18. DEFINE_RESPONSE_TABLE2(TOleDialog, TOleWindow, TDialog)
  19.   EV_OC_VIEWSETSITERECT,
  20. END_RESPONSE_TABLE;
  21.  
  22. //
  23. //
  24. //
  25. TOleDialog::TOleDialog(TWindow* parent, TResId resId, TModule* module)
  26.            :TOleWindow(parent, module), TDialog(parent, resId, module)
  27. {
  28.   // Register OCX class
  29.   //
  30.   static TRegisterOcxWnd regWnd(GetApplication()->GetHandle());
  31.  
  32.   // Override TDialog's desire to not be autocreated
  33.   //
  34.   SetFlag(wfAutoCreate);
  35. }
  36.  
  37. //
  38. //
  39. //
  40. TOleDialog::~TOleDialog()
  41. {
  42.   Destroy();
  43. }
  44.  
  45. //
  46. //
  47. //
  48. void
  49. TOleDialog::SetupWindow()
  50. {
  51.   // Call parents setup
  52.   //
  53.   TOleWindow::SetupWindow();
  54.   TDialog::SetupWindow();
  55.  
  56.   HWND hWnd = ::GetWindow(*this, GW_CHILD);
  57.   if (hWnd) {
  58.     // Check if it is a control class and if so, load it
  59.     //
  60.     HWND hWndControl = CheckChild(hWnd);
  61.  
  62.     // Loop through all the children and look for 'stub' windows
  63.     // that should be replaced with an OCX control...
  64.     //
  65.     while ((hWnd = ::GetWindow(hWnd, GW_HWNDNEXT)) != 0) {
  66.       if (hWndControl)
  67.         ::DestroyWindow(hWndControl);
  68.       hWndControl = CheckChild(hWnd);
  69.     }
  70.  
  71.     if (hWndControl)
  72.       ::DestroyWindow(hWndControl);
  73.   }
  74. }
  75.  
  76. //
  77. // Pass thru functions routed to TDialog base
  78. //
  79. bool
  80. TOleDialog::IdleAction(long idleCount)
  81. {
  82.   TOleWindow::IdleAction(idleCount);
  83.   return TDialog::IdleAction(idleCount);
  84. }
  85.  
  86. bool
  87. TOleDialog::PreProcessMsg(MSG& msg)
  88. {
  89.   if (TOleWindow::PreProcessMsg(msg) || TDialog::PreProcessMsg(msg))
  90.     return true;
  91.   return false;
  92. }
  93.  
  94. //
  95. // Override SetSiteRect from TOleWindow since we want to force
  96. // our OCX Controls to keep the size and position defined in
  97. // the resource file. This is done by simply returning false
  98. //
  99. bool
  100. TOleDialog::EvOcViewSetSiteRect(TRect far* rect)
  101. {
  102.   TOleWindow::EvOcViewSetSiteRect(rect);
  103.   return false;
  104. }
  105.  
  106. //
  107. // Check if the hWndChild is a placeholder for a control and if so
  108. // load it. Return hWndChild (if a control is found) so that the calling
  109. // procedure can destroy that window since we don't need that any longer
  110. //
  111. HWND
  112. TOleDialog::CheckChild(HWND hWndChild)
  113. {
  114.   char className [50];
  115.   if (::GetClassName(hWndChild, className, sizeof(className))) {
  116.     if (strcmp(className, OCX_STUB_CLASS) == 0) {
  117.       LoadControl(hWndChild);
  118.       return hWndChild;
  119.     }
  120.   }
  121.   return 0;
  122. }
  123.  
  124. //
  125. // Find out ProgId (from caption of control) and position for this
  126. // control and load it
  127. //
  128. void
  129. TOleDialog::LoadControl(HWND hControl)
  130. {
  131.   // Get stub control's location
  132.   //
  133.   TRect ControlRect;
  134.   ::GetWindowRect(hControl, &ControlRect);
  135.   TPoint TopLeft(ControlRect.left, ControlRect.top);
  136.   ::ScreenToClient(*this, &TopLeft);
  137.   TPoint BottomRight(ControlRect.right, ControlRect.bottom);
  138.   ::ScreenToClient(*this, &BottomRight);
  139.   ControlRect.Set(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y);
  140.  
  141.   // Get ProgId
  142.   //
  143.   char progId [80];
  144.   ::GetWindowText(hControl, progId, sizeof(progId));
  145.  
  146.   // Create control with specified progid at location
  147.   //
  148.   InsertControl(TString(progId), &ControlRect);
  149. }
  150.  
  151. //
  152. // Class to register and unregister the window class which acts as a
  153. // stub window for an OCX in a dialog
  154. //
  155. TRegisterOcxWnd::TRegisterOcxWnd(HINSTANCE hInst)
  156.                 :HAppInst(hInst)
  157. {
  158.   // Registration for OCX window
  159.   //
  160.   WNDCLASS wndClass;
  161.  
  162.   wndClass.style = CS_GLOBALCLASS;   // Global registration
  163.   wndClass.lpfnWndProc = ::DefWindowProc;
  164.   wndClass.cbClsExtra = 0;
  165.   wndClass.cbWndExtra = 0;
  166.   wndClass.hInstance = HAppInst;
  167.   wndClass.hIcon = 0;
  168.   wndClass.hCursor = 0;
  169.   wndClass.hbrBackground = 0;
  170.   wndClass.lpszMenuName = 0;
  171.   wndClass.lpszClassName = OCX_STUB_CLASS;
  172.  
  173.   RegisterClass(&wndClass);
  174. }
  175.  
  176. //
  177. // Unregister OCX stub-window class
  178. //
  179. TRegisterOcxWnd::~TRegisterOcxWnd()
  180. {
  181.   UnregisterClass("OCX", HAppInst);
  182. }
  183.  
  184.